﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.Public.Encrypt;

namespace YArchitech.Public
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdUpdata : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
		{
			try
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				Trace.WriteLine("start");
				bool flag = Program.OnUpdate(mainWindowHandle);
				Trace.WriteLine("check:" + flag);
				if (!flag)
				{
					Trace.WriteLine("check false:" + flag);
					string updateLastError = Program.GetUpdateLastError();
					YJKMessageBox.Information(updateLastError);
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				throw;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
